<!DOCTYPE html>
<html class="x-admin-sm">
<head>
<meta charset="UTF-8">
<title>新增</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="/css/font.css">
<link rel="stylesheet" href="/css/index.css">
<script type="text/javascript" src="/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="/js/index.js"></script>
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/layui-post.js"></script>
<script type="text/javascript" src="/js/xcity.js"></script>
<script type="text/javascript" src="/verify.js"></script>
</head>
<style type="text/css">
    .layui-col-md6{margin-bottom: 10px;}
    .layui-col-md12{margin-bottom: 10px;}
</style>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form layui-form-pane" lay-filter="editForm" id="edit">
            <div class="layui-card-body ">
                <div class="layui-tab layui-tab-card">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-col-md12">
                            <label class="layui-form-label"><span class='x-red'>* </span>优惠类型</label>
                            <div class="layui-input-block">
                                <select name="couponType" id="couponType" lay-verify="required"><option value="">请选择优惠类型</option></select>
                            </div>
                        </div>
                        <div class="layui-col-md12">
                            <label class="layui-form-label"><span class='x-red'>* </span>优惠面值</label>
                            <div class="layui-input-block">
                                <input type="number" name="parValue" autocomplete="off" placeholder="请输入优惠面值" lay-verify="required" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md12">
                            <label class="layui-form-label"><span class='x-red'>* </span>满减面值</label>
                            <div class="layui-input-block">
                                <input type="number" name="factValue" autocomplete="off" placeholder="请输入满减面值" lay-verify="required" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label"><span class='x-red'>* </span>生效时间</label>
                            <div class="layui-input-block">
                                <input class="layui-input" autocomplete="off" placeholder="请输入生效时间" lay-verify="required" name="effectTime" id="effectTime">
                            </div>
                        </div>
                        <div class="layui-col-md6">
                            <label class="layui-form-label"><span class='x-red'>* </span>失效时间</label>
                            <div class="layui-input-block">
                                <input class="layui-input" autocomplete="off" placeholder="请输入失效时间" lay-verify="required" name="failureTime" id="failureTime">
                            </div>
                        </div>
                        <div class="layui-col-md12">
                            <label class="layui-form-label"><span class='x-red'>* </span>使用说明</label>
                            <div class="layui-input-block">
                                <textarea class="layui-input" name="remark" placeholder="请输入使用说明" style="height: 100px;"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn" type="button" lay-filter="add" lay-submit="" id="submit">保存</button>
            </div>
        </form>
    </div>
</div>
<script>
$.ajaxSetup({contentType: "application/json; charset=utf-8"});
layui.use(['form','layer','laydate','layedit','upload'], function(){
    var form = layui.form,layer = layui.layer,upload = layui.upload,textInit;
    layui.laydate.render({elem: '#effectTime',theme: '#2f4554',type: 'date',trigger: 'click',min:minDate(),format:'yyyy-MM-dd'});
    layui.laydate.render({elem: '#failureTime',theme: '#2f4554',type: 'date',trigger: 'click',min:minDate(),format:'yyyy-MM-dd'});
    $.post(geturl()+'/enums/select?token='+sessionStorage.getItem("token"), JSON.stringify({parentEnumCode:"COUPON_TYPE",orderByAscType:"enumCode"}), function (res) {
        for(var key in res.data.COUPON_TYPE) $('#couponType').append('<option value="'+key + '">' + res.data.COUPON_TYPE[key] + '</option>');
        layui.form.render();
    }).done(function(){
        $.post(geturl()+'/cateringCoupon/select?token='+sessionStorage.getItem("token"), JSON.stringify({sysId:getQueryString("sysId")}), function (res) {
            for(var i in res.data){
                form.val("editForm", {
                    "couponType": res.data[i].couponType,
                    "parValue": res.data[i].parValue,
                    "factValue": res.data[i].factValue,
                    "effectTime": res.data[i].effectTime,
                    "failureTime": res.data[i].failureTime,
                    "remark": res.data[i].remark,
                });
                layui.form.render();
                textInit = JSON.stringify({ dataform: $("#edit").serializeArray() });
            }
        }, 'json');
    })
    //监听提交
    layui.form.on('submit(add)', function(data){
        data.field.sysId = getQueryString("sysId")
        var text = JSON.stringify({ dataform: $("#edit").serializeArray() });
        if(textInit == text) {
            layui.use('layer',function(){
                layer.msg("没有更改无需提交!",{icon:5,time:1000});
            })
        }else layuiPost(geturl()+'/cateringCoupon/update?token='+sessionStorage.getItem("token"),data.field,parent.layer.getFrameIndex(window.name));
        return false;
    });
});
</script>
</body>
</html>